Late in December 2019, the World Health Organisation (WHO) China Country Office obtained information about a severe pneumonia of an unknown cause, detected in the city of Wuhan in Hubei province, China. This later turned out to be the novel coronavirus disease (COVID-19), an infectious disease caused by severe acute respiratory syndrome coronavirus-2 (SARS-CoV-2) of the corona virus family. The disease causes respiratory illness characterised by primary symptoms like cough, fever, and in more acute cases, difficulty in breathing. WHO later declared covid-19 as a Pandemic because of its fast rate of spread across the Globe with over 2.7 Million confirmed cases and over 190,000 deaths as of April 24, 2020. The African continent started confirming its first cases in late January and mid-February of 2020 in some countries. The disease has since spread across 52 of the 54 Africa countries with over 27,000 confirmed cases and over 1,200 deaths as of April 24, 2020.
The covid_19_africa.csv dataset contains daily level information about the Covid-19 cases in Africa. It is a time series data and hence the number of cases on any given day is cumulative.I extracted the data from the covid_19_data.csv which was made available on kaggle. The R script that I used to prepare this dataset is also available on my Github repository. The original datasets can be found on John Hopkins University Github repository for covid_19.
Visualizations of Africa’s COVID-19 confirmed cases, deaths, and recovered cases by country.
Loading the required packages and setting a general theme for all the plots.
suppressMessages(library(tidyverse))
## Warning: package 'ggplot2' was built under R version 3.6.3
suppressMessages(library(lubridate))
suppressMessages(library(DT))
## Warning: package 'DT' was built under R version 3.6.3
suppressMessages(library(plotly))
theme_set(theme_classic())
Importing the dataset
covid_africa <- read_csv("covid_19_africa.csv")
# converting the classes of Confirmed, Deaths, and Recovered columns to class integer
covid_africa <- covid_africa %>%
mutate(Confirmed = as.integer(Confirmed),
Deaths = as.integer(Deaths),
Recovered = as.integer(Recovered),
Active = as.integer(Active))
datatable(covid_africa)
length(unique(covid_africa$Country))
## [1] 52
At the time of updating this script, only 52 of the 54 African countries recognized by the UN and WHO had confirmed cases.
Note that the latest number of cases on a given day is the cumulative sum of cases reported by end of the previous day.
latest <- covid_africa %>%
filter(ObservationDate == today() - 1 )
datatable(latest)
Interactive plot of weekly changes in the number COVID-19 cases in Africa
weekly_cases <- covid_africa %>%
# grouping by observationdate
group_by(ObservationDate) %>%
# obtaining the sum of cases for each day
summarise(Confirmed = sum(Confirmed), Deaths = sum(Deaths), Recovered = sum(Recovered), Active = sum(Active))
# creating a character vector of colors for the cases
colors <- c("Confirmed" = "orange", "Deaths" = "red", "Recovered" = "green", "Active" = "cyan2")
# plotting
p <- weekly_cases %>%
# placing all cases in a single column and their sums in another column
gather(Confirmed, Deaths, Recovered, Active, key = "cases", value = "number") %>%
# specifying the values on the x and y axes
ggplot(aes(x = ObservationDate, y = number)) +
# specifying the plot type
geom_line(aes(color = cases)) +
# setting the date labels
scale_x_date(date_labels = "%d-%b", date_breaks = "1 week") +
# manually changing the colors of the cases
scale_color_manual(values = colors) +
# setting parameters for x axis, plot title, and plot margin
theme(axis.text.x = element_text(angle = 45, hjust = 1),
plot.title = element_text(hjust = 0, size = 10, face = "bold"),
plot.margin = margin(1, 0, 0, 0, unit = "cm")) +
# setting the plot labels
labs(title = "Weekly changes in the number of COVID-19 cases in Africa",
x = "Date", y = "Number of cases")
# making the plot interactive
ggplotly(p)
Confirmed number of cases by country.
(latest_confirmed <- latest %>%
# reordering the countries by number of confirmed cases i.e highest to lowest
mutate(Country = fct_reorder(Country, Confirmed)) %>%
# specifying the values on the x and y axes
ggplot(aes(x = Country, y = Confirmed)) +
# setting parameters for the bar plots of confirmed cases by country
geom_bar(stat = "identity", show.legend = FALSE, fill = "orange", width = 0.6) +
# specifying and positioning of the bar labels
geom_text(aes(label = Confirmed), hjust = 0, size = 3) +
# flipping the x and y co-ordinates
coord_flip(clip = "off", expand = FALSE) +
# specifying desired parameters for the plot title and margin
theme(plot.title = element_text(hjust = 0, size = 10, face = "bold"),
plot.margin = margin(0, 1, 0, 0, unit = "cm")) +
# specifying the plot title
labs(title = "Africa's Confirmed COVID-19 cases by Country. 2020-04-24"))
Confirmed deaths by country.
(latest_deaths <- latest %>%
# reordering the countries by number of confirmed deaths i.e highest to lowest
mutate(Country = fct_reorder(Country, Deaths)) %>%
# specifying the values on the x and y axes
ggplot(aes(x = Country, y = Deaths)) +
# setting parameters for the bar plots of confirmed deaths by country
geom_bar(stat = "identity", show.legend = FALSE, fill = "red", width = 0.6) +
# specifying and positioning of the bar labels
geom_text(aes(label = Deaths), hjust = 0, size = 3) +
# flipping the x and y co-ordinates
coord_flip(clip = "off", expand = FALSE) +
# specifying desired parameters for the plot title and margin
theme(plot.title = element_text(hjust = 0, size = 10, face = "bold"),
plot.margin = margin(0, 1, 0, 0, unit = "cm")) +
# specifying the plot title
labs(title = "Africa's Deaths from COVID-19 by Country. 2020-04-24"))
Recovered cases by country.
(latest_recovered <- latest %>%
# reordering the countries by number of recovered cases i.e highest to lowest
mutate(Country = fct_reorder(Country, Recovered)) %>%
# specifying the values on the x and y axes
ggplot(aes(x = Country, y = Recovered)) +
# setting parameters for the bar plots of confirmed recoveries by country
geom_bar(stat = "identity", show.legend = FALSE, fill = "green", width = 0.6) +
# specifying and positioning of the bar labels
geom_text(aes(label = Recovered), hjust = 0, size = 3) +
# flipping the x and y co-ordinates
coord_flip(clip = "off", expand = FALSE) +
# specifying desired parameters for the plot title and margin
theme(plot.title = element_text(hjust = 0, size = 10, face = "bold"),
plot.margin = margin(0, 1, 0, 0, unit = "cm")) +
# specifying the plot title
labs(title = "Africa's Recovered cases from COVID-19 by Country. 2020-04-24"))
Active cases by country.
(latest_active <- latest %>%
# reordering the countries by number of active cases i.e highest to lowest
mutate(Country = fct_reorder(Country, Active)) %>%
# specifying the values on the x and y axes
ggplot(aes(x = Country, y = Active)) +
# setting parameters for the bar plots of active cases by country
geom_bar(stat = "identity", show.legend = FALSE, fill = "cyan2", width = 0.6) +
# specifying and positioning of the bar labels
geom_text(aes(label = Active), hjust = 0, size = 3) +
# flipping the x and y co-ordinates
coord_flip(clip = "off", expand = FALSE) +
# specifying desired parameters for the plot title and margin
theme(plot.title = element_text(hjust = 0, size = 10, face = "bold"),
plot.margin = margin(0, 1, 0, 0, unit = "cm")) +
# specifying the plot title
labs(title = "Africa's Active cases of COVID-19 by Country. 2020-04-24"))